<j:ebuttons
  [searchPlaceholder]="'BasicArchives::UI:Document.JButtons.SearchPlaceholder' | abpLocalization"
  [editState]="editState"
  [backBtnVisible]="false"
  [selectBtnVisible]="false"
  [listBtnVisible]="false"
  [searchDividerVisible]="false"
  (saveBtnClick)="save()"
  (giveupBtnClick)="giveup()"
  (newBtnClick)="new()"
  (copyBtnClick)="copy()"
  (deleteBtnClick)="delete()"
  (submitBtnClick)="submit()"
  (approveBtnClick)="approve()"
  (unapproveBtnClick)="unapprove()"
  (refreshBtnClick)="refresh()"
  (searchBtnClick)="search($event)"
>
</j:ebuttons>
<form nz-form [formGroup]="validateForm">
  <nz-card class="main-card">  
    <nz-tabset nzType="card">
      <nz-tab [nzTitle]="'BasicArchives::UI:Document.CardTitle.Base' | abpLocalization">
        <div nz-row>
          <div nz-col [nzSpan]="8">
            <nz-form-item>
              <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="code">
                <a nz-button nzType="link" class="ref-form-label" (click)="uniqueCodeSetting()">
                  {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.Code' | abpLocalization }}
                </a>
              </nz-form-label>
              <nz-form-control [nzSm]="14" [nzXs]="24" nzHasFeedback>
                <input
                  nz-input
                  id="code"
                  formControlName="code"
                  [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.Code' | abpLocalization"
                  [readonly]="codeInputDisabled || readonlyMode"
                  [ngClass]="{ 'input-disabled': codeInputDisabled }"
                  nz-tooltip
                  [nzTooltipTitle]="getErrorMessage('code')"
                  [nzTooltipVisible]="validateForm.get('code')?.invalid && validateForm.get('code')?.touched"
                  nzTooltipPlacement="top"
                />
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="8">
            <nz-form-item>
              <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="orderTypeId">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.OrderTypeId' | abpLocalization }} 
              </nz-form-label>
              <nz-form-control [nzSm]="14" [nzXs]="24" nzHasFeedback>
                <widget-entity-ref-select
                  [formControlName]="'orderTypeId'"
                  [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.OrderTypeId' | abpLocalization"
                  [idKey]="'id'"
                  [labelKey]="'displayName'"
                  [showSelect]="showOrderTypeSelect"
                  [getDetail]="getOrderTypeDetail"
                  readonly
                  [nzDisabled]="readonlyMode"
                  nz-tooltip
                  [nzTooltipTitle]="getErrorMessage('orderTypeId')"
                  [nzTooltipVisible]="validateForm.get('orderTypeId')?.invalid && validateForm.get('orderTypeId')?.touched"
                  nzTooltipPlacement="top"
                >
                </widget-entity-ref-select>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="8">
            <nz-form-item>
              <nz-form-label [nzSm]="8" [nzXs]="24" nzRequired nzFor="businessDate">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.BusinessDate' | abpLocalization }} 
              </nz-form-label>
              <nz-form-control [nzSm]="14" [nzXs]="24" nzHasFeedback>
                <nz-date-picker
                  id="businessDate"
                  formControlName="businessDate"
                  [nzPlaceHolder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.BusinessDate' | abpLocalization"
                  style="width: 100%;"
                  [nzDisabled]="readonlyMode"
                  nz-tooltip
                  [nzTooltipTitle]="getErrorMessage('businessDate')"
                  [nzTooltipVisible]="validateForm.get('businessDate')?.invalid && validateForm.get('businessDate')?.touched"
                  nzTooltipPlacement="top"
                >
                </nz-date-picker>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="8">
            <nz-form-item>
              <nz-form-label [nzSm]="8" [nzXs]="24" nzFor="supplierId">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.SupplierId' | abpLocalization }} 
              </nz-form-label>
              <nz-form-control [nzSm]="14" [nzXs]="24" nzHasFeedback>
                <widget-entity-ref-select
                  [formControlName]="'supplierId'"
                  [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.SupplierId' | abpLocalization"
                  [idKey]="'id'"
                  [labelKey]="'name'"
                  [showSelect]="showSupplierSelect"
                  [getDetail]="getSupplierDetail"
                  readonly
                  [nzDisabled]="readonlyMode"
                  nz-tooltip
                  [nzTooltipTitle]="getErrorMessage('supplierId')"
                  [nzTooltipVisible]="validateForm.get('supplierId')?.invalid && validateForm.get('supplierId')?.touched"
                  nzTooltipPlacement="top"
                >
                </widget-entity-ref-select>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="8">
            <nz-form-item>
              <nz-form-label [nzSm]="8" [nzXs]="24" nzFor="operatorId">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.OperatorId' | abpLocalization }} 
              </nz-form-label>
              <nz-form-control [nzSm]="14" [nzXs]="24" nzHasFeedback>
                <widget-entity-ref-select
                  [formControlName]="'operatorId'"
                  [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.OperatorId' | abpLocalization"
                  [idKey]="'id'"
                  [labelKey]="'name'"
                  [showSelect]="showOperatorSelect"
                  [getDetail]="getOperatorDetail"
                  readonly
                  [nzDisabled]="readonlyMode"
                  nz-tooltip
                  [nzTooltipTitle]="getErrorMessage('operatorId')"
                  [nzTooltipVisible]="validateForm.get('operatorId')?.invalid && validateForm.get('operatorId')?.touched"
                  nzTooltipPlacement="top"
                >
                </widget-entity-ref-select>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="8">
            <nz-form-item>
              <nz-form-label [nzSm]="8" [nzXs]="24" nzFor="mark">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.Mark' | abpLocalization }} 
              </nz-form-label>
              <nz-form-control [nzSm]="14" [nzXs]="24" nzHasFeedback>
                <textarea
                  nz-input
                  id="mark"
                  formControlName="mark"
                  [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisition.Mark' | abpLocalization"
                  [readonly]="readonlyMode"
                  [nzAutosize]="{ minRows: 2, maxRows: 6 }"
                  nz-tooltip
                  [nzTooltipTitle]="getErrorMessage('mark')"
                  [nzTooltipVisible]="validateForm.get('mark')?.invalid && validateForm.get('mark')?.touched"
                  nzTooltipPlacement="top"
                >
                </textarea>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
      </nz-tab>
    </nz-tabset>
  </nz-card>
  <nz-card class="line-card">
    <nz-tabset nzType="card">
      <nz-tab [nzTitle]="'BasicArchives::UI:Document.CardTitle.Details' | abpLocalization">
        <nz-table
          #childTable
          nzSize="middle"
          [nzData]="children.controls"
          [nzShowPagination]="false"
          [nzFrontPagination]="false"
          [nzShowSizeChanger]="true"
          [nzScroll]="{ x: '100%', y: '100%' }"
          [nzBordered] = "true"
          [nzNoResult] = "noResult"
          (contextmenu)="contextMenu($event, menuTable)"
        >
          <nz-dropdown-menu #menuTable="nzDropdownMenu">
            <ul nz-menu>
              <li nz-menu-item (click)="addChild()">{{ 'BasicArchives::UI:Document.ContextMenu.Add' | abpLocalization }}</li>
            </ul>
          </nz-dropdown-menu>
          <ng-template #noResult class="no-result">
          </ng-template>
          <thead>
            <tr>
              <th [nzWidth]="'80px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.LineNo' | abpLocalization }}
              </th>
              <th [nzWidth]="'200px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.ItemMasterId' | abpLocalization }}
              </th>
              <th [nzWidth]="'150px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.ItemCode' | abpLocalization }}
              </th>
              <th [nzWidth]="'150px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.ItemSpec' | abpLocalization }}
              </th>
              <th [nzWidth]="'120px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.Quantity' | abpLocalization }}
              </th>
              <th [nzWidth]="'120px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.RemainingQuantity' | abpLocalization }}
              </th>
              <th [nzWidth]="'150px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.UnitId' | abpLocalization }}
              </th>
              <th [nzWidth]="'120px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.UnitPrice' | abpLocalization }}
              </th>
              <th [nzWidth]="'180px'">
                {{ 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.DeliveryDate' | abpLocalization }}
              </th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let child of children.controls; let i = index" (contextmenu)="contextMenu($event, menuRow)">
              <nz-dropdown-menu #menuRow="nzDropdownMenu">
                <ul nz-menu>
                  <li nz-menu-item (click)="addChild()">{{ 'BasicArchives::UI:Document.ContextMenu.Add' | abpLocalization }}</li>
                  <li nz-menu-item (click)="removeChild(i)">{{ 'BasicArchives::UI:Document.ContextMenu.Delete' | abpLocalization }}</li>
                </ul>
              </nz-dropdown-menu>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <nz-input-number
                      [formControl]="child.get('lineNo')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.LineNo' | abpLocalization"
                      [nzMin]="1"
                      [nzStep]="10"
                      style="width: 100%;"
                      [nzDisabled]="readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'lineNo')"
                      [nzTooltipVisible]="child.get('lineNo')?.invalid && child.get('lineNo')?.touched"
                      nzTooltipPlacement="top">
                    </nz-input-number>
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <widget-entity-ref-select
                      [formControl]="child.get('itemMasterId')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.ItemMasterId' | abpLocalization"
                      [idKey]="'id'"
                      [labelKey]="'name'"
                      [showSelect]="showItemMasterSelect"
                      [getDetail]="getItemMasterDetail"
                      (selectedValueChanged)="onItemMasterSelect($event, child)"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'itemMasterId')"
                      [nzTooltipVisible]="child.get('itemMasterId')?.invalid && child.get('itemMasterId')?.touched"
                      nzTooltipPlacement="top"
                      [nzDisabled]="readonlyMode"
                    >
                    </widget-entity-ref-select>
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <input
                      nz-input
                      [formControl]="child.get('itemCode')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.ItemCode' | abpLocalization"
                      [readonly]="true || readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'itemCode')"
                      [nzTooltipVisible]="child.get('itemCode')?.invalid && child.get('itemCode')?.touched"
                      nzTooltipPlacement="top"
                    />
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <input
                      nz-input
                      [formControl]="child.get('itemSpec')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.ItemSpec' | abpLocalization"
                      [readonly]="true || readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'itemSpec')"
                      [nzTooltipVisible]="child.get('itemSpec')?.invalid && child.get('itemSpec')?.touched"
                      nzTooltipPlacement="top"
                    />
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <nz-input-number
                      [formControl]="child.get('quantity')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.Quantity' | abpLocalization"
                      [nzMin]="0"
                      [nzPrecision]="2"
                      style="width: 100%;"
                      [nzDisabled]="readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'quantity')"
                      [nzTooltipVisible]="child.get('quantity')?.invalid && child.get('quantity')?.touched"
                      nzTooltipPlacement="top">
                    </nz-input-number>
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <nz-input-number
                      [formControl]="child.get('remainingQuantity')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.RemainingQuantity' | abpLocalization"
                      [nzMin]="0"
                      [nzPrecision]="2"
                      style="width: 100%;"
                      [nzDisabled]="readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'remainingQuantity')"
                      [nzTooltipVisible]="child.get('remainingQuantity')?.invalid && child.get('remainingQuantity')?.touched"
                      nzTooltipPlacement="top">
                    </nz-input-number>
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <widget-entity-ref-select
                      [formControl]="child.get('unitId')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.UnitId' | abpLocalization"
                      [idKey]="'id'"
                      [labelKey]="'unit.displayName'"
                      [showSelect]="getShowUnitSelect(child)"
                      [getDetail]="getUnitDetail"
                      (selectedValueChanged)="onUnitSelect($event, child)"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'unitId')"
                      [nzTooltipVisible]="child.get('unitId')?.invalid && child.get('unitId')?.touched"
                      nzTooltipPlacement="top"
                      [nzDisabled]="readonlyMode"
                    >
                    </widget-entity-ref-select>
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <nz-input-number
                      [formControl]="child.get('unitPrice')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.UnitPrice' | abpLocalization"
                      [nzMin]="0"
                      [nzPrecision]="2"
                      style="width: 100%;"
                      [nzDisabled]="readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'unitPrice')"
                      [nzTooltipVisible]="child.get('unitPrice')?.invalid && child.get('unitPrice')?.touched"
                      nzTooltipPlacement="top">
                    </nz-input-number>
                  </nz-form-control>
                </nz-form-item>
              </td>
              <td>
                <nz-form-item>
                  <nz-form-control nzHasFeedback>
                    <nz-date-picker
                      [formControl]="child.get('deliveryDate')"
                      [placeholder]="'BasicArchives::ModelPlaceHolder:Joy.Erp.BasicArchives.Procurements.PurchaseRequisitionLine.DeliveryDate' | abpLocalization"
                      style="width: 100%; max-width: 180px; min-width: 120px; box-sizing: border-box;"
                      [nzDisabled]="readonlyMode"
                      nz-tooltip
                      [nzTooltipTitle]="getControlErrorMessage(child, 'deliveryDate')"
                      [nzTooltipVisible]="child.get('deliveryDate')?.invalid && child.get('deliveryDate')?.touched"
                      nzTooltipPlacement="top"
                    >
                    </nz-date-picker>
                  </nz-form-control>
                </nz-form-item>
              </td>
            </tr>
          </tbody>
        </nz-table> 
      </nz-tab>
    </nz-tabset>
  </nz-card>
</form> 